#include <stdio.h>
#include <stdlib.h>

int main()
{
    int step;
    int i;
    int j;
    int l;
    int n;
    int p[111];
    int q[111];
    printf("We will list out the position of the disks as 0,1,2\nsuppose,they are all at place 2 at first\n");
    printf("we want them to goto place 0\n" );
    printf("We will list the position of the disk from the small disks to the big ones \nSo,HOW MANY LEVELS?\n");
    scanf ("%d",&n);
    for (i = 0 ;i < n; i++)
        p[i] = 2;
    p[n] = 0;
    q[n] = 0;
    printf("\n");
    int flag = 1;
    for (step = 1 ; flag; step++)
    {
        for(i = n - 1; i >= 0; i--)
        {
            int find = n;
            for (j = i + 1; j <= n - 1; j++)
                if (p[j] != q[j])
                {
                    find = j;
                    break;
                }
            q[i] = (3 - (p[find] + q[find])) % 3;
        }
        for (i = 0; i <= n - 1; i++)
            if (p[i] != q[i])
            {
                p[i] = q[i];
                break;
            }
        flag = 0;
        printf("Step %d : ", step);
        for(i = 0; i <= n - 1; i++)
        {
            flag += p[i];
            printf("%d",p[i]);
        }
        printf("\nA:");
        for(l = n - 1; l >= 0; l--)
        {
            if(p[l] == 2) printf("%d",l);
        }
        printf("\nB:");
        for(l = n - 1; l >= 0; l--)
        {
            if(p[l] == 1) printf("%d",l);
        }
        printf("\nC:");
        for(l = n - 1; l >= 0; l--)
        {
            if(p[l] == 0) printf("%d",l);
        }
        printf("\n\n");
    }
    printf ("good!");
    return 0;
}
